﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EncuentraloSilverlight.ServiceReference2;
using System.Windows.Navigation;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Browser;

namespace EncuentraloSilverlight
{
	public partial class OnSale : Page
	{
		public OnSale()
		{
			// Required to initialize variables
			InitializeComponent();
            
            Service2Client webservice = new Service2Client();

            webservice.FindAllProductsCompleted += (obj, eventarg) =>
                {
                    // all seller tengo que sacarle el product!!
                    ObservableCollection<Product> prod = eventarg.Result;
                    string currentuser = Cookie.GetCookie("EncuentraloUser");
                    //Products_Datagrid.ItemsSource = prod.Where(k => k.Seller.Name.Equals(currentuser));
                };
            
            webservice.FindAllProductsAsync();
		}

        private void KeyUp_TextBox_CommonExpressSearch(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Cookie.SetCookie("EncuentraloSearch", TextBox_CommonExpressSearch.Text);
                NavigationService.Navigate(new Uri("/Views/BusquedaExpress.xaml", UriKind.Relative));
            }
        }

        private void Click_Button_CommonExpressSearch(object sender, RoutedEventArgs e)
        {
            Cookie.SetCookie("EncuentraloSearch", TextBox_CommonExpressSearch.Text);
            NavigationService.Navigate(new Uri("/Views/BusquedaExpress.xaml", UriKind.Relative));
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Service2Client webservice = new Service2Client();

            foreach (Product item in Products_Datagrid.SelectedItems)
            {
                webservice.ModifyProductAsync(item.ProductID, item);
            }

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Cookie.SetCookie("EncuentraloUser", "");
            NavigationService.Navigate(new Uri("/Views/Home.xaml", UriKind.Relative));
        }



	}
}